package example;

import auto.base.TestNgSpringContextTests;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.JSONPObject;
import com.google.gson.JsonObject;
import com.kipa.http.service.impl.HttpServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.testng.Assert;
import org.testng.annotations.Test;
import org.testng.collections.Maps;

import java.util.Map;

/**
 * @Author: hongjie.lin
 * @Date: 2021/10/14 15:01
 */
public class HttpExample extends TestNgSpringContextTests {

    @Autowired
    private HttpServiceImpl httpService;

    @Test
    public void getExample1(){
        String url = "https://bee-konggatewaydev.abite.com/decorate-api/installApiController/getInstallDetail?installNo=AZ21101200027";
        String result = httpService.get(url);
        System.out.println(result);
    }

    @Test
    public void postExample1(){
        String url = "https://bee-konggatewaydev.abite.com/mgt-api/auth/loginValidateCode";
        Map<String, String> header = Maps.newHashMap();
        header.put("Content-Type","application/json");
        String json = "{\n" +
                "  \"areaCode\": \"+86\",\n" +
                "  \"mobile\": \"18859272529\",\n" +
                "  \"deviceId\": \"yummy\",\n" +
                "  \"origin\": 1\n" +
                "}";
        JSONObject result = JSON.parseObject(httpService.post(url, header, json, true));
        int code = result.getIntValue("code");
        System.out.println(code);
        Assert.assertEquals(code,200);

    }
}
